package com.springinaction.ch06.config;

import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.tiles3.TilesConfigurer;

/**
 * @author ssk
 * @Title: RootConfig
 * @ProjectName SpringInAction
 * @Description: TODO
 * @date 18-12-7下午9:33
 */
@Configuration
@ComponentScan(
        basePackages = {"com.springinaction.ch06.web", "com.springinaction.ch06.data"},
        excludeFilters = {
                @ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)
        }
)
public class RootConfig {
        @Bean
        public MessageSource messageSource(){
                 // 第一种方法 实现<s:message> 这个是从根目录找
                // ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
               // messageSource.setBasename("messages");
                // 第二种方法 实现<s:message> 这个可以选 classpath根目录 file文件系统
                ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
                messageSource.setBasename("classpath:messages");
                return messageSource;
        }
        @Bean
        public TilesConfigurer TilesConfigurer(){
                TilesConfigurer tilesConfigurer = new TilesConfigurer();
                tilesConfigurer.setDefinitions("tiles.xml");
                return tilesConfigurer;
        }

}
